//#include <base.js>
//#include <openlayersExt.js>
//#include <event.js>


/**
* 
* Classe CWN2.ContainerBuilder - Build the Containr
* 
* @namespace CWN2
* @class ContainerBuilder
* 
*/

CWN2.ContainerBuilder = {
	
	/**
	* 
	* Build the Container (Panel or Viewport)
	* 
	* @method build
	* 
	*/ 
	
	build: function(div) {

		if(CWN2.base.DEBUG) {
			console.log('CWN2.ContainerBuilder');
		} 	
		
			
		var panelItems = [];
		
		// pannello mappa
		var mapPanel = CWN2.MapPanelBuilder.build();
		panelItems.push(mapPanel);
		
		// pannello legenda		
		if (CWN2.configuration.legend) {
			var legendPanel = CWN2.LegendPanelBuilder.build();
			panelItems.push(legendPanel);
		}
		
		return this[CWN2.configuration.layout.type](div,panelItems);
		

	},
	
	/**
	* 
	* Build the Viewport
	* 
	* @method viewport
	* 
	*/ 

	viewport: function(div,panelItems) {
		
		// opzioni di base
		var options = this.setBasicOptions(panelItems);
		// ritorno la viewport
		return new Ext.Viewport(options);

	},
	
	/**
	* 
	* Build the Panel
	* 
	* @method panel
	* 
	*/ 
	
	panel: function(div,panelItems) {

		// opzioni di base
		var options = this.setBasicOptions(panelItems);
		// opzioni per panel
		options.renderTo = div;
		if (CWN2.configuration.layout.height) {
		    options.height = CWN2.configuration.layout.height;
		}
	    if (CWN2.configuration.layout.width) {
		    options.width = CWN2.configuration.layout.width;
		}
		// ritorno il panel
		return new Ext.Panel(options);
	},
	
	/**
	* 
	* Build the Window
	* 
	* @method window
	* 
	*/ 
	
	window: function(div,panelItems) {
	    
		// opzioni di base
		var options = this.setBasicOptions(panelItems);
		// opzioni per window
		options.closeAction = "hide";
		if (CWN2.configuration.layout.height) {
		    options.height = CWN2.configuration.layout.height;
		}
	    if (CWN2.configuration.layout.width) {
		    options.width = CWN2.configuration.layout.width;
		}	
		// ritorno la window
		return new Ext.Window(options);
	},
	
	/**
	* 
	* Set the basic options for the component
	* 
	* @method setBasicOptions
	* 
	*/ 
	
	setBasicOptions: function(panelItems) {
	    var options = {
			defaults: {
				frame: true,
				split: true
			},
			id: "cwn2-container",
	        layout: "border",
			hideBorders: false,
			forceLayout: true,
			closeAction: "hide",
			items: panelItems      
	    };
		return options;
	}
	
};	
	

